#!/bin/bash
unset LINKS LYNX
LOCAL="Bras"
HOST="http://pcdsh01.on.br/ispy.asp"

LINKS=$(which links0 2> /dev/null)
LYNX=$(which lynx 2> /dev/null)

echo -n $LINKS
test -e $LINKS && echo $LINKS-ok

echo -n $LYNX
test -e $LYNX && echo $LYNX-ok

##################### FUNÇÕES ########################
function _links(){
        DATA=$(links -dump 1 $HOST|tr -d '|' | grep -i $LOCAL|awk '{print $2}')
        HORA=$(links -dump 1 $HOST|tr -d '|' | grep -i $LOCAL|awk '{print $3}')
}
function _lynx(){
        DATA=$(lynx -dump $HOST|grep -i $LOCAL|awk '{print $2}')
        HORA=$(lynx -dump $HOST|grep -i $LOCAL|awk '{print $3}')
}

######################################################
if test -e $LINKS; then
        echo "links ..."
        _links
elif test -e $LYNX; then
        echo "lynx ..."
        _lynx
else
        echo Ops...
        echo "para execução deste script é necessário um navegador tipo texto (links ou lynx).";
        exit 0;
fi

echo $DATA - $HORA
